var grid;
var form;
var form1;
$(function () {

    //加载该页面前，先判断该模块的权限
    //获取当前登录的用户的权限
    var permission = document.cookie.split(";")[1].split("=")[1];
    var b = String(permission).split('');
    var moudle32 = b[8];
    //如果模块权限为1，即只能查询此模块下的数据，不能进行修改（禁用和重置密码不能使用）
    if (moudle32 == 1) {
        //禁用新建、黑名单模板下载、系统上传
        $("#addBtn").css('display', 'none');
        $("#downloadBtn").css('display', 'none');
        $("#uploadBtn").css('display', 'none');
    }
    // ----------------

    var pageNo = 1;
    var pageSize = 5;
    var grid_selector = "#grid-table";
    var pager_selector = "#grid-pager";

    //初始化数据表格
    grid = $(grid_selector).jqGrid({
        datatype: "json",
        url: 'findBlacklist',
        mtype: 'POST',
        page: pageNo,
        postData: {
            'UID': $("#input2").val(),
            'name': $("#input3").val(),
            'source': $("#select1 option:selected").text(),
            'state': $("#select2 option:selected").text(),
            /*'departmentId':0,*/
        },
        height: 380,
        width: 300,
        colNames: ['证件号码', '名称', '黑名单来源', '列入黑名单日期', '状态'],
        colModel: [
            {name: 'UID', index: 'UID', sortable: false, align: 'center'},
            {name: 'name', index: 'name', sortable: false, align: 'center'},
            {name: 'source', index: 'source', sortable: false, align: 'center'},
            {name: 'addtime', index: 'addtime', sortable: false, align: 'center'},
            {name: 'state', index: 'state', sortable: false, align: 'center'},
        ],
        viewrecords: true,
        rowNum: pageSize,
        rownumbers: false,//添加左侧行号
        rowList: [5, 10, 15],
        pager: pager_selector,
        altRows: true,
        multiselect: false,
        loadComplete: function (data) {
            var table = this;
            setTimeout(function () {
                updatePagerIcons(table);
            }, 0);
            var h = $(window).height() - ($('#grid-pager')[0].offsetHeight + 15) - ($('.result-table .box')[0].offsetTop + $('.content .col-xs-12')[0].offsetTop + $('.ui-jqgrid-bdiv')[0].offsetTop + 3);
            $('.ui-jqgrid-bdiv').height(h);
        },
        autowidth: true,
        jsonReader: jsonReader,   // json中代表实际模型数据的入口
        rownumWidth: 55,
        prmNames: prmNames,
        recordtext: "显示 {0} - {1} 条 , 共 {2} 条",
        emptyrecords: "没有记录",
        loadtext: "正在加载...",
        pgtext: "第 {0} 页  ,共 {1} 页"
    });
    //初始化分页条
    showNavGrid(grid_selector, pager_selector);
    //初始化信息校验表单
    form = $("#addform").validate({
        errorElement: 'div',
        errorClass: 'help-block messages',
        focusInvalid: false,
        highlight: validateHighlight,
        success: validateSuccess,
        errorPlacement: errorPlacement
    });
    form1 = $("#Editform").validate({
        errorElement: 'div',
        errorClass: 'help-block messages',
        focusInvalid: false,
        highlight: validateHighlight,
        success: validateSuccess,
        errorPlacement: errorPlacement
    });

    //查询
    $("#queryBtn").click(function () {
        var filters = {
            'UID': $("#input2").val(),
            'name': $("#input3").val(),
            'source': $("#select1 option:selected").text(),
            'state': $("#select2 option:selected").text(),
        }
        grid.jqGrid("setGridParam", {postData: filters, page: 1});
        grid.trigger('reloadGrid');


    });
    //清空
    $("#clearBtn").click(function () {
        $("#input2").val(null).trigger("change");
        $("#input3").val(null).trigger("change");
        $("#select1").val(null).trigger("change");
        $("#select2").val(null).trigger("change");

    });

    //黑名单下载


    //文件上传
    $("#uploadBtn").click(function () {


    });

});

function checkUID() {
    var UID = $("#input2").val();
    if (!/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9X]$/.test(UID)) {

        $("#message").html("身份证格式错误，请重新输入");
        return false;
    } else {
        $("#message").html("身份证格式正确");
    }
}


